#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time      :2021/11/8 10:25
# @Author    :cjw
from httprunner import HttpRunner, Config, Step, RunRequest
from use_httprunner_api.setting import APP_ID, APP_SECRET, TENANT_ACCESS_TOKEN


class TestToken(HttpRunner):
	config = Config("获取企业自建应用token").verify(False).variables(**{
		"app_id": APP_ID,
		"app_secret": APP_SECRET,
		"tenant_access_token": TENANT_ACCESS_TOKEN
	}).export("token")

	teststeps = [
		Step(
			RunRequest("获取token")
				.post("$tenant_access_token")
				.with_json(
				{
					"app_id": "$app_id",
					"app_secret": "$app_secret"
				}
			)
				.extract()
				.with_jmespath("body.tenant_access_token", "token")
				.validate()
				.assert_equal("status_code", 200)
				.assert_equal("body.code", 0)
		)
	]


if __name__ == '__main__':
	TestToken().test_start()
